#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    extern char **environ;
    pid_t id = fork();
    if(id == 0)
    {
        printf("我是子进程:%d\n", getpid());

        //1.execl("/bin/ls", "ls", "-a", "-l", NULL);

        //char *myargv[] = {"ls", "-l", "-a", NULL};
        //2.execv("/bin/ls", myargv);

        //3.execlp("ls", "ls", "-a", "-l", NULL);

        //4.execvp("ls", myargv);

        //char *const myenv[] = {"MYENV=YouCanSeeMe", NULL};//自定义环境变量
        //execle("./Otherproc/otherproc", "otherproc", NULL, myenv);
        putenv("MYENV=YouCanSeeMe");
        execle("./Otherproc/otherproc", "otherproc", NULL, environ);

        exit(1);
    }
    sleep(5);
    int status = 0;
    printf("我是父进程:%d\n", getpid());
    waitpid(id, &status, 0);
    printf("child exit code:%d\n", WEXITSTATUS(status));
    return 0;
}